const App = getApp();

// pages/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navList: [
      {
      title: '查课表',
      icon: '/assets/icon/容器.png',
      path:'/pages/course/course'
    },
    {
      title:'查成绩',
      icon:'/assets/icon/容器 1.png',
      path:'/pages/score/score'
    },
    {
      title:'查考勤',
      icon:'/assets/icon/容器 2.png',
      path:''
    },
    {
      title:'查校历',
      icon:'/assets/icon/容器 3.png',
      path:''
    }
  ],
  weekData:[],
  isCourse:false,
  nowWeekContent:'这周没有课喽，快去充实一下自己吧'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
 
 

  
  
  },
nav(e){
    const Index = e.currentTarget.dataset.index;
    const path = this.data.navList[Index].path;
    if (path == '/pages/course/course') {
      wx.switchTab({
        url: path,
      })
      return;
    }
    wx.navigateTo({
      url: path,
    })
},



















  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const courseList = wx.getStorageSync('course')
    const week = wx.getStorageSync('courseNowWeek')
    let weekData=[];
    if (courseList&&week) {
      courseList.forEach(item=>{
        if (item.weeks.includes(week)) {
         weekData.push({"course":item.name,
         "address":item.address})
        }
      })
   
      if (weekData.length !==0) {
    
        this.setData({
          weekData,
          isCourse:false,
          nowWeekContent:'这周没有课喽，快去充实一下自己吧'
        })
      }else{
  
        this.setData({
          isCourse:true,
          nowWeekContent:'这周没有课喽，快去充实一下自己吧'
        })
      }
     
      
     
      } else{
       this.setData({
        isCourse:true,
        nowWeekContent:"正在获取课程数据"
      })
      wx.switchTab({
        url: this.data.navList[0].path,
        success:()=>{
          setTimeout(()=>{
            wx.switchTab({
              url: "/pages/index/index"
            })
           },1000)
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide(e) {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})